#include "plook_u32u8u16n16_binca_s.h"
#include "binsearch_u32u8.h"
#include "rtwtypes.h"

uint32_T plook_u32u8u16n16_binca_s(uint8_T u, const uint8_T bp[], uint32_T
  maxIndex, uint16_T *fraction)
{
  uint32_T bpIndex;
  if (u <= bp[0U]) {
    bpIndex = 0U;
    *fraction = 0U;
  } else if (u < bp[maxIndex]) {
    uint8_T bpLeftVar;
    bpIndex = binsearch_u32u8(u, bp, maxIndex >> 1U, maxIndex);
    bpLeftVar = bp[bpIndex];
    *fraction = (uint16_T)(((uint32_T)(uint8_T)((uint32_T)u - bpLeftVar) << 16) /
      (uint8_T)((uint32_T)bp[bpIndex + 1U] - bpLeftVar));
  } else {
    bpIndex = maxIndex;
    *fraction = 0U;
  }

  return bpIndex;
}
